/**
 * 
 */
package edu.umuc.cmsc495_final_project;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * @author paul.lipp
 * 
 */
public class titlePanel extends JFrame implements allGUI {

	public JPanel titleBar;

	private int frameWidth = 0;
	private int frameHeight = 0;

	private JPanel userArea;
	private JPanel timeArea;

	private JLabel currentUserTitle;
	private JLabel currentUserInfo;
	private JLabel currentUserCredential;

	protected JButton managerOverride;
	protected JButton logout;

	protected Boolean manager = false;

	public titlePanel(){}
	
	public titlePanel(boolean manager){

		this.manager = manager;
		System.out.println("opening title panel, manager is " + manager);
		
		setName("Title Panel");
		setSize(panelWidth, (int) (panelHeight*.135));
		setVisible(true);
		setLayout(null);
		removeNotify();  
		setUndecorated(true);  
		addNotify();  

		mainBody();
	}	
	
	// normal user
	public void setCurrentUser(String userInfo, credential userCredential) {
		currentUserInfo.setText(userInfo);
		currentUserCredential.setText(userCredential.toString());
	}
	
	// manager override
	public void setCurrentUser(String userInfo, credential userCredential, credential managerCredential) {
		currentUserInfo.setText(userInfo);
		currentUserCredential.setText(userCredential.toString() + " / " + managerCredential.toString());
		timeArea.setBorder(BorderFactory.createLineBorder(Color.RED, 5));
	}

	@Override
	public void mainBody() {
		Font font = new Font("Verdana", Font.BOLD, 40);
		
		frameWidth = (int)(panelWidth*.98);
		frameHeight = (int)(panelHeight*.11);
		
		titleBar = new JPanel();
		titleBar.setBounds((int)(panelWidth*.01),(int)(panelWidth*.01),frameWidth, frameHeight);//titleBarXY, titleBarXY, frameWidth, frameHeight);
		titleBar.setVisible(true);
		titleBar.setLayout( new GridBagLayout() );
		
		//getContentPane().
		add(titleBar);
		
		//setup for layout
		GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.HORIZONTAL;

		
		//user area
		userArea = new JPanel();
		userArea.setVisible(true);
		userArea.setBorder(BorderFactory.createLineBorder(Color.black));
		
		userArea.setLayout(new GridLayout(2,1));

		currentUserTitle = new JLabel("Current User: ", JLabel.CENTER);
		currentUserTitle.setFont(font);
		userArea.add(currentUserTitle);
		
		currentUserInfo = new JLabel("", JLabel.CENTER);
		currentUserInfo.setFont(font);
		userArea.add(currentUserInfo);
		
		
		//time area
		timeArea = new JPanel();
		timeArea.setVisible(true);
		timeArea.setBorder(BorderFactory.createLineBorder(Color.black));
		timeArea.setLayout(new GridLayout(2,1));
		
		// area time panel to time area
		TimePanel tp = new TimePanel();
		tp.setFont(font);
		timeArea.add(tp);
		
		// adds current user credential level to time area
		currentUserCredential = new JLabel("", JLabel.CENTER);
		currentUserCredential.setFont(font);
		timeArea.add(currentUserCredential);
		
		//manager area button
		managerOverride = new JButton();
		managerOverride.setLayout(new BorderLayout());
		
		// manager labels
		JLabel label1 = new JLabel("MANAGER", JLabel.CENTER);
		label1.setFont(font);
		JLabel label2 = new JLabel("OVERRIDE", JLabel.CENTER);
		label2.setFont(font);
		managerOverride.add(BorderLayout.NORTH,label1);
		managerOverride.add(BorderLayout.SOUTH,label2);		   
		managerOverride.setBackground(Color.RED);	
		
		// checks if current user is a manager or not
		if( manager )
			managerOverride.setVisible(false); // hide
		else
			managerOverride.setVisible(true); // show
		
		//logout area button
		logout = new JButton("Log-out");
		logout.setVisible(true);
		logout.setFont(font);		
		
		// add panels to titleBar
		c.fill = GridBagConstraints.BOTH;
		c.weightx = 0.5;
		c.gridwidth = 2;
		c.gridx = 0;
		c.gridy = 0;
		titleBar.add(userArea, c);
		
		c.fill = GridBagConstraints.BOTH;
		c.weightx = 0.5;
		c.gridwidth = 2;
		c.gridx = 2;
		c.gridy = 0;
		titleBar.add(timeArea,c);
		
		c.fill = GridBagConstraints.BOTH;
		c.weightx = 0.5;
		c.gridwidth = 1;
		c.gridx = 4;
		c.gridy = 0;
		titleBar.add(managerOverride,c);
		
		c.fill = GridBagConstraints.BOTH;
		c.weightx = 0.5;
		c.gridwidth = 1;
		c.gridx = 5;
		c.gridy = 0;
		titleBar.add(logout,c);
	}
}